package pcb.control.commands 
{
	import com.intel.core.Application;
	import com.intel.patterns.cairngorm.CairngormEvent;
	import com.intel.utils.Debugger;
	import pcb.control.events.LoadDataEvent;
	import pcb.models.LessonStateModel;
	
	/**
	 * ...
	 * @author Fintan Boyle
	 */
	public class Cmd_getLessonId extends AbstractCommand 
	{
		
		public function Cmd_getLessonId() 
		{
			
		}
		
		override public function execute(event:CairngormEvent):void 
		{
			Debugger.traceOut("Cmd_getLessonId > execute()");
			
			var lessonId:String;
			
			if (event.data != undefined) { //coming from menu
				lessonId = event.data;
				Debugger.traceOut("coming from menu " + lessonId);
			}else if (Application.root.loaderInfo.parameters.id != null) {
				lessonId = Application.root.loaderInfo.parameters.id;
			} else { //must be url parameter id that is needed
				//lessonId = Application.root.loaderInfo.parameters.id;
				lessonId = "pcb_intro";
			}
			
			
			Debugger.traceOut("Cmd_getLessonIdCmd_getLessonIdCmd_getLessonIdlessonId " + lessonId);
			//expecting a url parameter
			if (lessonId != null) {
				proceedWithLesson(lessonId);
			}else if (Application.PREVIEW_IN_IDE) {
				//var dummyId:String = "browsing-internet";
				var dummyId:String = "pcb_intro";
				Debugger.traceOut("PREVIEW_IN_IDE " + Application.PREVIEW_IN_IDE + " with " + dummyId);
				proceedWithLesson(dummyId);
			}
			
		}
		
		private function proceedWithLesson(id:String):void 
		{
			models.lessonStateModel.lessonId = id;
			models.playerStateModel.setCurrentLessonId(models.lessonStateModel.lessonId);
			
			models.lessonStateModel.status = LessonStateModel.PREINITIALISED;
			
			var evSwf:LoadDataEvent = new LoadDataEvent(LoadDataEvent.LOAD_LESSON_SWF);
			evSwf.dispatch();
		}
		
	}
	
}